package calao.util;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;

public abstract class LogHandler 
{

	final static SimpleDateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss.SSS");
		
	abstract public void handle(LogRecord record);
	
	public boolean handles(LogLevel level)
	{
		return true;
	}	
	
	void printTo(LogRecord record, PrintWriter writer)
	{
		writer.write(TIME_FORMAT.format(record.time));
		writer.write(" [");
		writer.write(record.level.getId());
		writer.write("] ");
		record.writeMessage(writer);
		writer.flush();		
	}

}
